package com.satan.juc.demo8;

public class MutextDemo {
    private static Mutex mutex = new Mutex();
    private static int count = 0;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                mutex.lock();
                try {
                    System.out.println(Thread.currentThread().getName() + "抢到了锁");
                    count++;
//                    Thread.sleep(1000);
                } finally {
                    mutex.unlock();
                }
            });
            thread.start();
        }
        Thread.sleep(1000);
        System.out.println(count);
    }
}